<template>
	<view>
		<!-- 帖子详情信息 -->
		<common-list :item="demo" isdetail  @doComment="doComment" @doShare="doShare" @follow="follow" @dosupport="dosupport" style="margin-top;">
			
			<view>
				<image v-for="(item,index) in demo.titlepic" 
				@click="preview(index)"
				:src="item" class="w-100" mode="widthFix"></image>
			</view> 
		</common-list>
		<divider></divider>
		<view class="p-2 font-md font-weight-bold">
			最新评论 3
			<text class="iconfont icon-zhuanfa" style="margin-left: 500rpx;" @click="zhuanfa"></text>
		</view>
		<view class="px-2">
			<view class="uni-comment-list">
				
			</view>
			
		</view>
		
		<moreShare ref="share"></moreShare>
		<!-- 占位 -->
		<view style="height: 100rpx;"></view>
		<bottom-input @submit="submit"></bottom-input>
	</view>
</template>

<script>
	import commonList from '@/components/common/common-list.vue'
	import bottomInput from '@/components/common/bottom-input.vue';
	import moreShare from '@/components/common/more-share.vue';
	export default {
		components:{
			commonList,
			bottomInput,
			moreShare
		},
		data() {
			return {
				demo:[],
				_id:'',
				//当前帖子信息
				info:{
					username:"昵称",
					userpic:"../../static/tabber/default.jpg",
					newstime:"2021-12-1 15:30",
					isFollow:false,
					title:"我是标题",
					titlepic:"../../static/demo/datapic/12.jpg",
					support:{
						type:"unsupport",
						support_count:1,
						unsupport_count:2
					},
					comment_count:2,
					share_num:2,
					content:"火影忍者：名人汤",
					images:[{
						url:"https://c-ssl.duitang.com/uploads/blog/202012/12/20201212214216_bba1e.thumb.1000_0.jpg"
					},{
						url:"http://i0.hdslb.com/bfs/article/903728905fd673af0c92817092c7b1dcae9cd4c5.jpg"
					},
					{
						url:"http://i0.hdslb.com/bfs/article/f42df921963eff42a15eaf55044c5fbae3803fc7.jpg"
					}]
				}
			}
		},
		// onShow() {
		// 	this.getdata()
		// },
		onLoad(e){
			//初始化
			if(e.detail){
				this.__init(JSON.parse(e.detail))
			}
			this._id=e._id
			this.getdata()
		},
		// onShareAppMessage(res) {
		// 		      return {
		// 		        title: '微信分享测试',
		// 		        path: '页面路径' (可携带参数)
		// 		      }
		// 		    },
		// onShareTimeline() {},
		computed: {
			imagesList() {
				return this.info.images.map(item=>item.url) 
			}
		},
		
		methods: {
			async getdata()
			{
					const res = await uniCloud.callFunction({
						name: "tiezi",
						data: {
							action: 'getOne',
							_id:this._id
						}
					})
					this.demo=res.result.data[0]
					console.log(this.demo.titlepic)
				
			},
			//转发
			zhuanfa(e){
				this.$refs.share.open()
			},
			onBackPress() {
				this.$refs.share.close()
			},
			__init(data){
				//修改标题
				uni.setNavigationBarTitle({
					title:data.title
				})
				//请求api
			},
			 //点击评论
			 doComment(){
				 
			 },
			 //点击分享
			 doShare(){
				 
			 },
			 follow(){
				 this.demo.isFollow=true 
				 uni.showToast({
					 title:"关注成功"
				 })
			 },
			 //顶踩操作
			 dosupport(e){
				
			 	// 之前操作过
				if (this.demo.support.type === e.type) {
					return uni.showToast({
						title: '你已经操作过了',
						icon: 'none'
					});
				}
			 	let msg = e.type === 'support' ? '顶' : '踩'
			 	// 之前没有操作过
			 	if (this.demo.support.type === '') {
			 		this.demo.support[e.type+'_count']++
			 	}else if(this.demo.support.type === 'support' && e.type === 'unsupport'){				
			 		// 顶 - 1
			 		this.demo.support.support_count--;
			 		// 踩 + 1
			 		this.demo.support.unsupport_count++;
			 	}else if(this.demo.support.type === 'unsupport' && e.type === 'support'){			   
			 		// 顶 + 1
			 		this.demo.support.support_count++;
			 		// 踩 - 1
			 		this.demo.support.unsupport_count--;
			 	}
			 	this.demo.support.type = e.type
			 	uni.showToast({
			 		title: msg
			 	});
			 },
			 // 预览图片
			 preview(index){
				 console.log(this.demo.titlepic)
				 console.log(this.imagesList)
			 	// 预览图片
			 	uni.previewImage({
			 		current:index,
			 		urls:this.demo.titlepic
			 	});
			 },
			 // 提交评论
			submit(data){
				console.log(data)
				// if(data === ''){
				// 	return uni.showToast({
				// 		title: '评论不能为空',
				// 		icon: 'none'
				// 	});
				// }
				// uni.showLoading({
				// 	title: '评论中...',
				// 	mask: false
				// });
				// this.$H.post('/post/comment',{
				// 	fid:this.reply_id,
				// 	data:data,
				// 	post_id:this.info.id
				// },{
				// 	token:true
				// }).then(res=>{
				// 	uni.hideLoading()
				// 	this.getComments()
				// }).catch(err=>{
				// 	uni.hideLoading()
				// })
			},
		}
	}
</script>

<style>

</style>
